<?php
/**
 * Created by PhpStorm.
 * User: majiawen
 * Date: 2018/3/13
 * Time: 10:39
 */
namespace app\admin\service;

use app\common\Model\BusinessUpdate;
use app\common\Model\Freight;
use think\Db;

class BusinessUpdateService
{
    static function shaohuoBusinessUpdateLog($uid)
    {
        $BusinessUpdate = new BusinessUpdate();
        $last = $BusinessUpdate->where(['type' =>$BusinessUpdate::TYPE_SHAOHUO ])->order('version_no desc')->find();
        $now_data = Db::name('func_class')
            ->where([
                'status' => \app\common\Model\FuncClass::STATUS_NORMAL,
                'is_del' => \app\common\Model\FuncClass::IS_DEL_FALSE,
            ])
            ->order('sort desc')
            ->field([
                'fc_id',
                'func_name',
                'widget_ids',
                'sort'
            ])
            ->select();
        $now_data = json_encode($now_data);
        $data = empty($last['data'])?'':$last['data'];
        $version_no = empty($last['version_no'])?0:$last['version_no'];
        if($now_data!=$data){
            $insert = [
                'type' =>1,
                'deal_uid'=> $uid,
                'data' => $now_data,
                'version_no'=> $version_no+1,
            ];
            Db::name('business_update')->insert($insert);
        }
    }
    static function freightBusinessUpdateLog($uid)
    {
        $BusinessUpdate = new BusinessUpdate();
        $last = $BusinessUpdate->where(['type' => $BusinessUpdate::TYPE_FREIGHT])->order('version_no desc')->find();
        $freight = new Freight();
        $now_data = $freight->where([
                'is_del' => $freight::IS_DEL_FALSE,
            ])
            ->field([
                'f_id',
                'province_region_id',
                'city_region_id',
                'price',
            ])
            ->select();
        $now_data = json_encode($now_data);
        $data = empty($last['data'])?'':$last['data'];
        $version_no = empty($last['version_no'])?0:$last['version_no'];
        if($now_data!=$data){
            $insert = [
                'type' =>1,
                'deal_uid'=> $uid,
                'data' => $now_data,
                'version_no'=> $version_no+1,
            ];
            Db::name('business_update')->insert($insert);
        }
    }

}